<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>型号确认任务</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    <style type="text/css">
        #taskList,#errorRecordText {
            border: 1px solid #959595;
        }
        #taskList tr th,#errorRecord tr th{
            background-color: #6ecac5;
        }
        #taskList tr th, #taskList tr td ,#errorRecord tr th, #errorRecord tr td{
            border: 1px #d6d6d6 dashed;
            font-size: 15px;
            text-align: center;
            height: 30px;
            font-family:"微软雅黑";
        }

    </style>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border: none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border: none;">
            <form id="ff">
                <div style="margin-bottom:20px">
                    <label class="item-label">品类：</label>
                    <!--data-options="multiple:true"-->
                    <select id="categorySelect" class="easyui-combobox" style="width:174px;" name="categoryCode" ></select>
                    <!--<label class="item-label">开始时间：</label>-->
                    <!--<input type="text" id="reportBeginDate" class="easyui-datebox" data-options="formatter:dateFormatter,parser:dateParser" name="reportBeginDate" />-->
                    <!--<label class="item-label">开始时间：</label>-->
                    <!--<input type="text" id="reportEndDate" class="easyui-datebox" data-options="formatter:dateFormatter,parser:dateParser" name="reportEndDate" />-->

                    <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px;margin-left:40px;" onclick="searchBy()">查询</a>

                </div>
            </form>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" style="width:100%" data-options="fitColumns:true,scrollbarSize:0">
                <thead>
                <tr>
                    <th data-options="field:'categoryCode',align:'center'" width="40">品类</th>
                    <th data-options="field:'missionName',align:'center'" width="40">任务名称</th>
                    <th data-options="field:'remarks',align:'center'" width="60">原因</th>
                    <th data-options="field:'reportYear',align:'center',formatter:tjpj" width="140">条件</th>
                    <th data-options="field:'cmField',align:'center',formatter:qrzd" width="60">确认字段</th>
                    <th data-options="field:'groups',align:'center'" width="60">总组数</th>
                    <th data-options="field:'createDate',align:'center'" width="40">创建时间</th>
                    <th data-options="field:'endTime',align:'center'" width="40">截止时间</th>
                    <th data-options="field:'status',align:'center',formatter:statusFormatter" width="40">状态</th>
                    <th data-options="field:'action',formatter:actions,align:'center'" width="50">操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        setNav();
        initUserCategorySelect("categorySelect");
        var height = $(window).height();
        var nav_height = $("#nav")._outerHeight();
        var form_height = $("#ff").height();

        $("#datagrid").css("max-height", (height - nav_height - form_height - 20));
        $("#datagrid").datagrid({
            pagination: true,
            rownumbers: true,
            singleSelect: true,
            checkOnSelect: false,
            toolbar: [{
                text: "添加任务",
                handler: function () {
                    window.parent.addTab("添加任务", "/webapp/pages/product/modelConfirm/rwAdd.html");
                }
            }],
            onBeforeSelect: function () {
                return false;
            }
        }).datagrid("getPager").pagination({
            onSelectPage: searchBy
        });
        aRecords("型号任务发布","/webapp/pages/product/modelConfirm")
        searchBy(1, 100);
    });

    function actions(val, row) {
        return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' " +
            "style='width:90px;' onclick='manage(\"" + row.id + "\")'>进入</a>&nbsp;&nbsp;" ;
    }
    function tjpj(val, row) {
        var tj="";
        if(row.sdCt &&row.sdCt.length>0 ){
            tj=tj+"销售数据条件：{"
            row.sdCt[0].pcpVO.forEach(function(p) {
                // console.log(p);
                tj=tj+ p.prop.code;
                if("EQUAL" == p.comparator){
                    tj=tj+"=";
                }else if("BETWEEN" == p.comparator){
                    tj=tj+"[范围]:";
                }else if("LITTLE_EQUAL" == p.comparator){
                    tj=tj+"<=";
                }else if("GREAT_EQUAL" == p.comparator){
                    tj=tj+">=";
                }
                tj=tj+p.prop.value+" && ";
            }
            )
            tj=tj+"}"
        }
        var xhtj ="";
        if(row.complexProperties){
            xhtj=xhtj+"型号条件：{"
            row.complexProperties.forEach(function(ep) {
                if(ep.andOr == "AND"){
                    xhtj=xhtj+"and["
                    ep.pcpVO.forEach(function(p) {
                        xhtj=xhtj+ p.prop.code;
                        if("EQUAL" == p.comparator){
                            xhtj=xhtj+"=";
                        }else if("GREAT" == p.comparator){
                            xhtj=xhtj+">";
                        }else if("LITTLE_EQUAL" == p.comparator){
                            xhtj=xhtj+"<=";
                        }else if("GREAT_EQUAL" == p.comparator){
                            xhtj=xhtj+">=";
                        }else if("LITTLE" == p.comparator){
                            xhtj=xhtj+"<";
                        }else if("NOT_EQUAL" == p.comparator){
                            xhtj=xhtj+"<>";
                        }else if("CONTAIN" == p.comparator){
                            xhtj=xhtj+"[包含]：";
                        }
                        xhtj=xhtj+p.prop.value+" && ";


                    })
                    xhtj=xhtj+"]"
                }
            })
            xhtj=xhtj+"}"

        }
        return tj+xhtj;

    }
    function qrzd(val, row) {
        var tj="全品类";
       if(row.cmField[0]){
           tj = row.cmField
       }
        return tj;

    }
    function disableOne(id, entityStatus) {
        $.messager.confirm("提示", "您确定删除该记录吗？", function (flag) {
            if (flag) {
                $.ajax({
                    url: config.url + "/dataReport/" + id,
                    type: 'DELETE',
                    xhrFields: {withCredentials: true},
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                });
            }
        });
    }
    function manage(id) {
        window.parent.addTab("进入", "/webapp/pages/product/modelConfirm/rwlist.html?id=" + id);
    }
    function searchBy(page, size) {
        var data = getFormData(document.getElementById("ff"));
        data['page'] = page || 1;
        data['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||100;
        $.ajax({
            url: config.url + "/modelConfirm/page",
            type:'post',
            data: transfer(data),
            dataType: "json",
            xhrFields: {withCredentials: true},
            beforeSend: function () {
                $.messager.progress({
                    title: "请稍等",
                    interval: 50,
                    text: "数据加载中..."
                });
            },
            complete: function () {
                $.messager.progress("close");
            },
            success: function (data) {
                $.messager.progress("close");
                if(data){
                    globalData = data;
                    $("#datagrid").datagrid("loadData",data);
                }
            },
            error: function (data) {
                // console.log(data);
                $.messager.progress("close");
            }
        });
    }
    function dateFormatter(date) {
        // console.log("date:",date);
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        if(m<10){
            m="0"+m;
        }
        var d = date.getDate();
        if(d<10){
            d="0"+d;
        }
        return y+'-'+m+'-'+d;
    }
    function dateParser(date) {

    }
</script>
</html>